﻿using System;
using System.Text;

namespace Alex.Library.Web.Ajax
{
    public interface ISerializeHelper
    {
        /// <summary>
        /// 如果值为null是否序列化输出
        /// </summary>
        bool IncludeNull { get; set; }
        /// <summary>
        /// 将对象序列化为字符串
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="obj">对象</param>
        /// <param name="encoding">字符编码</param>
        /// <returns>序列化后的字符串</returns>
        string Serialize<T>(T obj, Encoding encoding);        
        /// <summary>
        /// 使用UTF8字符编码将对象序列化为字符串
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="obj">对象</param>
        /// <returns>序列化后的字符串</returns>
        string Serialize<T>(T obj);
        /// <summary>
        /// 将对象序列化为字符串
        /// </summary>        
        /// <param name="obj">对象</param>
        /// <param name="encoding">字符编码</param>
        /// <returns>序列化后的字符串</returns>
        string Serialize(object obj, Encoding encoding);
        /// <summary>
        /// 使用UTF8字符编码将对象序列化为字符串
        /// </summary>        
        /// <param name="obj">对象</param>
        /// <returns>序列化后的字符串</returns>
        string Serialize(object obj);
        /// <summary>
        /// 将字符串中反序列化为对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="serializeString">字符串</param>
        /// <param name="encoding">字符编码</param>
        /// <returns>反序列化后的对象</returns>
        T Deserialize<T>(string serializeString, Encoding encoding);       
        /// <summary>
        /// 使用UTF8字符编码将字符串反序列化为对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="serializeString">字符串</param>
        /// <returns>反序列化后的对象</returns>
        T Deserialize<T>(string serializeString);
        /// <summary>
        /// 将字符串中反序列化为对象
        /// </summary>
        /// <param name="serializeString">字符串</param>
        /// <param name="type">反序列化对象的类型</param>
        /// <param name="encoding">字符编码</param>
        /// <returns>反序列化后的对象</returns>
        object Deserialize(string serializeString, Type type, Encoding encoding);
        /// <summary>
        /// 使用UTF8字符编码将字符串反序列化为对象
        /// </summary>
        /// <param name="serializeString">字符串</param>
        /// <param name="type">反序列化对象的类型</param>        
        /// <returns>反序列化后的对象</returns>
        object Deserialize(string serializeString, Type type);
    }
}
